package com.example.black.myapplication.androidframwork;

import android.content.Context;
import android.support.v7.widget.AppCompatButton;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.Button;

/**
 * <pre>
 *     author : 28476
 *     e-mail : hao.wang@1hai.cn
 *     time   : 2018/11/01/9:56
 *     desc   :
 *     version: 1.0
 * </pre>
 */

public class MyButton extends AppCompatButton {

    public static final String TAG = MyButton.class.getSimpleName();

    public MyButton(Context context) {
        super(context);
    }

    public MyButton(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        String action = "no action";
        switch (event.getAction())
        {
            case MotionEvent.ACTION_DOWN:
                action = "down";
                break;
            case MotionEvent.ACTION_MOVE:
                action = "move";
                break;
            case MotionEvent.ACTION_UP:
                action = "up";
                break;
        }
        Log.e(TAG, "My Button dispatchTouchEvent: "+ event.getAction()+"desc "+action);
         super.dispatchTouchEvent(event);
        return true;
    }

    public boolean onTouchEvent(MotionEvent event){
        String action = "no action";
        switch (event.getAction())
        {
            case MotionEvent.ACTION_DOWN:
                action = "down";
                break;
            case MotionEvent.ACTION_MOVE:
                action = "move";
                break;
            case MotionEvent.ACTION_UP:
                action = "up";
                break;
        }
        Log.e(TAG, "My Button onTouchEvent: "+ event.getAction()+"desc "+action);
        super.onTouchEvent(event);
        return true;
    }
}
